package yartiss.engine.simulation.energy.profiles.consumption;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import yartiss.engine.simulation.IEnergyConsumptionProfile;

public class ConsumptionProfileFactory {
	
	private static final Map<String, IEnergyConsumptionProfile> profiles = new HashMap<String, IEnergyConsumptionProfile>();
	
	
	static {
		final List<IEnergyConsumptionProfile> profilesList = new ArrayList<IEnergyConsumptionProfile>();
		profilesList.add(new ConstantEnergyConsumptionProfile());
		profilesList.add(new InstantaneousConsAtBeginning());
		
		for (IEnergyConsumptionProfile p : profilesList) {
			profiles.put(p.getName(), p);
		}
		profiles.put("default", new ConstantEnergyConsumptionProfile());
	}
	
	public static void registerConsumptionProfile(IEnergyConsumptionProfile profile){
		profiles.put(profile.getName(), profile);
	}
	
	public static IEnergyConsumptionProfile newIntance(String type){
		if(profiles.containsKey(type))
			return profiles.get(type).cloneProfile();
		throw new IllegalArgumentException("ConsumptionProfileFactory : "+ type+" : not found profile");
	}
	
	public static String [] getAvailableProfiles(){
		String [] availableProfiles = new String [profiles.size()];
		
		int i=0;
		for (String p : profiles.keySet()) {
			availableProfiles[i++] = p;
		}
		return availableProfiles;
	}
}
